<template>
  <div class="nsw-container" style="width: 90%; margin: auto; min-height: 500px">
    <h1 style="margin: 40px 0">任务管理</h1>
    <div class="search-form">
      <el-form :model="params" inline label-width="90px" size="small">
        <el-form-item label="任务状态">
          <el-select v-model="params.status" placeholder="请选择" clearable style="width: 240px">
            <el-option :value="1" label="待接收"></el-option>
            <el-option :value="2" label="进行中"></el-option>
            <el-option :value="3" label="已完成"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="设计师">
          <el-input v-model="params.designerId" placeholder="请输入" clearable style="width: 240px"></el-input>
        </el-form-item>
        <el-form-item label="最小年龄">
          <el-input v-model.number="params.minAge" clearable style="width: 240px"></el-input>
        </el-form-item>
        <el-form-item label="最大年龄">
          <el-input v-model.number="params.maxAge" clearable style="width: 240px"></el-input>
        </el-form-item>
        <el-form-item label="服装分类">
          <el-select v-model="params.gender" placeholder="请选择" clearable style="width: 240px">
            <el-option :value="1" label="男装"></el-option>
            <el-option :value="2" label="女装"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="服装类型">
          <el-select v-model="params.type" placeholder="请选择" clearable style="width: 240px">
            <el-option :value="0" label="内衬"></el-option>
            <el-option :value="1" label="上衣"></el-option>
            <el-option :value="2" label="外套"></el-option>
            <el-option :value="3" label="裤装"></el-option>
            <el-option :value="4" label="裙装"></el-option>
            <el-option :value="5" label="套装"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="成本">
          <el-input v-model.number="params.cost" style="width: 240px"></el-input>
        </el-form-item>
        <el-form-item label="设计师等级">
          <el-input v-model.number="params.level" style="width: 240px"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="table">
      <el-table :data="tableData" stripe>
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-table :data="props.row.requires" stripe>
              <el-table-column label="服装分类" align="center" prop="gender">
                <template slot-scope="scope">
                  {{ scope.row.gender === 1 ? "男装" : "女装" }}
                </template>
              </el-table-column>
              <el-table-column label="服装类型" align="center" prop="types">
                <template slot-scope="scope">
                  <span v-if="scope.row.types === 0">内衬</span>
                  <span v-if="scope.row.types === 1">上衣</span>
                  <span v-if="scope.row.types === 2">外套</span>
                  <span v-if="scope.row.types === 3">裤装</span>
                  <span v-if="scope.row.types === 4">裙装</span>
                  <span v-if="scope.row.types === 5">套装</span>
                </template>
              </el-table-column>
              <el-table-column label="最小年龄" align="center" prop="minAge"></el-table-column>
              <el-table-column label="最大年龄" align="center" prop="maxAge"></el-table-column>
              <el-table-column label="服装风格" align="center" prop="style"></el-table-column>
              <el-table-column label="面料要求" align="center" prop="material"></el-table-column>
              <el-table-column label="最大成本" align="center" prop="cost"></el-table-column>
              <el-table-column label="设计师等级" align="center" prop="level"></el-table-column>
              <el-table-column label="具体需求" align="center" prop="require"></el-table-column>
              <el-table-column label="功能描述" align="center" prop="functionality"></el-table-column>
            </el-table>
          </template>
        </el-table-column>
        <el-table-column label="任务ID" align="center" width="80" prop="usTask.orderId"></el-table-column>
        <el-table-column label="任务状态" align="center" prop="usTask.status"></el-table-column>
        <el-table-column label="任务创建时间" align="center" prop="usTask.createTime"></el-table-column>
        <el-table-column label="任务更新时间" align="center" prop="usTask.updateTime"></el-table-column>
      </el-table>
      <el-pagination
        class="pageList"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="params.size"
        :current-page.sync="params.startPage"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        style="text-align: center; margin: 30px 0"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { getTaskList } from "@/api/task";
export default {
  name: "task",
  data() {
    return {
      params: {
        startPage: 1,
        size: 10,
        status: null,
        designerId: null,
        minAge: null,
        maxAge: null,
        gender: null,
        type: null,
        cost: null,
        level: null
      },
      tableData: [
        {
          "usTask": {
            "id": 1,
            "orderId": 1,
            "status": 1,
            "designerId": 4,
            "createTime": "2023-06-22T11:51:39",
            "updateTime": "2023-06-23T15:22:29"
          },
          "requires": [
            {
              "id": 1,
              "taskId": 1,
              "minAge": 10,
              "maxAge": 18,
              "gender": 0,
              "types": 1,
              "functionality": "休闲服装",
              "style": "国风",
              "material": "全棉",
              "cost": 500,
              "level": 2,
              "require": "要最好的"
            }
          ]
        },
      ],
      total: 0,
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    getList() {
      getTaskList(this.params)
        .then((res) => {
          // this.tableData = res;
          this.total = res.length;
        })
        .catch((err) => {});
    },
    handleQuery() {
      this.params.startPage = 1;
      this.getList();
    },
    handleSizeChange(val) {
      this.params.size = val;
      this.params.startPage = 1;
      this.getList();
    },
    handleCurrentChange(val) {
      this.params.startPage = val;
      this.getList();
    }
  },
};
</script>
